<?php
$cs=Yii::app()->getClientScript();
$cs->registerScriptFile('http://maps.google.com/maps/api/js?sensor=false', CClientScript::POS_HEAD);
$cs->registerScriptFile('/scripts/jquery-1.6.4.min.js', CClientScript::POS_HEAD);
?>

<h2>Partnerzy Wczasopedii</h2>
<p>W tych biurach nie tylko kupisz wycieczkę.<br>
Tu możesz uzyskać podstawowe i zweryfikowane informacje o rynku turystycznym i o najważniejszych podmiotach na nim działających.</p><br>
<div id="agents_map"><!-- . --></div>

<script type='text/javascript'>
  var agents_map;
  var piatek = new google.maps.LatLng(52.0688122, 19.4797444);       // Piątek near Łódź
  var iterator = 0;
  var info_window = new google.maps.InfoWindow();

  var markers = [
    <?php foreach($geo_users as $key => $val) : ?>
      {
      <?php foreach($val as $key2 => $val2) : ?>
        <?php echo $key2; ?>:'<?php echo $val2; ?>',
      <?php endforeach; ?>
        end:''
      },
    <?php endforeach; ?>
    {}
  ];


  function initialize() {
    var map_options = {
      center: piatek,
      zoom: 6,                                                    // zoom Poland
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    agents_map = new google.maps.Map(document.getElementById("agents_map"), map_options);
  }

  function processMarker(marker) {
    if (!jQuery.isEmptyObject(marker)) {
      var latlng = marker.latlng.split(',');
      var gmarker = new google.maps.Marker({
        map       : agents_map,
        position  : new google.maps.LatLng(latlng[0], latlng[1]),
        animation: google.maps.Animation.DROP,
      });

      google.maps.event.addListener(gmarker, 'click', function() {
		info_window.close();
		info_window.setContent(marker.point_desc);
		info_window.setPosition(gmarker.position);
		info_window.open(agents_map, gmarker);
		//console.log('otwieram: ' + );
      });
    }
  }

  jQuery(document).ready(function(jQuery){
    initialize();
    // iterate markers
    for (var i = 0; i < markers.length; i++) {
      processMarker(markers[iterator++]);
    }
  });
</script>
